<template>

</template>

<script>
    import JsEncrypt from 'jsencrypt'
    import axios from 'axios'
    export default {
        data() {
          return {
              username: 'hello',
              password: 'fdsfadf'
          }
        },
        methods: {
            encryptData(getPublicKey, data) {

                // 实例化对象
                let encrypt = new JsEncrypt();

                // 设置公钥
                encrypt.setPublicKey(getPublicKey);

                // 返回加密的数据
                return encrypt.encrypt(data);
            },
            submit() {
                axios({
                    method: 'post',
                    url: '',
                }).then(res => {
                    // res为后端返回的key，如同下面这样
　　　　　　　　　　　　//let res = 'MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCa+VHPOwxi0re/GhWApLl6WQMoTKazQsPp66AD8CKt2TaPrwv+dDFdQ5jP9xRbalGhLhEBlDq20oOCuIwWAI7/s0QTTvjYIBd+yWKzuRp0E+Qe7DqIE0pMrTi/ELkqibehYIvJ4sIEM+Wj9R007WT/64vGG/FaPsK9RsZiGShOAQIDAQAB'

                    let password = this.encryptData(res, password);
                    axios({
                        method: 'post',
                        url: '',
                        data: {
                            username: this.username,
                            password: password
                        }
                    }).then(ress => {
                        console.log(ress);
                    })
                })
            }
        }
    }
</script>

<style>

</style>